#include "mainlogin.h"
#include "ui_mainlogin.h"

MainLogin::MainLogin(QWidget *parent, AdminData *newData) : QMainWindow(parent), ui(new Ui::MainLogin)
{
    ui->setupUi(this);
    this->data = newData;

}

MainLogin::~MainLogin()
{
    delete ui;
}

void MainLogin::on_newUserButton_clicked()
{
    NewUser *createAccount = new NewUser(this, data);
    createAccount->show();
}

void MainLogin::on_loginButton_clicked()
{
    //qDebug() << data->getUsers().at(0).getUserID();
    users=&(data->getUsers());
    int r = 0;
    while(r<users->size()){
        if(ui->nameEdit->text().compare(users->at(r).getUserID())==0){
                if(users->at(r).getType()==ADMIN){
                    this->hide();
                    AdminWindow *w = new AdminWindow(this, data);
                    w->show();
                    break;

                }
                else if(users->at(r).getType()==CHAIR){
                    this->hide();
                    ChairWindow *w = new ChairWindow(this, data);
                    w->show();
                    break;
                }
                else{
                    this->hide();
                    InstructorWindow *w = new InstructorWindow(this, data);
                    w->show();
                    break;

                }
        }
        else{
            ui->nameEdit->clearFocus();
            ui->nameEdit->setPlaceholderText("Enter a valid ID here");
            palette.setColor(QPalette::Text, Qt::red);
            ui->nameEdit->setPalette(palette);
        }
    }
}

void MainLogin::on_nameEdit_cursorPositionChanged(int arg1, int arg2)
{
    palette.setColor(QPalette::Text, Qt::black);
    ui->nameEdit->setPalette(palette);
}


